﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Visa_InfoAddForm.aspx.cs" Inherits="FS.Web.BLL.Visa_info.Visa_InfoAddForm" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title> 
    <link href="/Themes/Scripts/EasyUI/easyui.css" rel="stylesheet" type="text/css" />
    <link href="/Themes/Styles/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/Validator/JValidator.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/artDialog.source.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/iframeTools.source.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/FunctionJS.js" type="text/javascript"></script>    
    <script src="/Themes/Scripts/EasyUI/jquery.easyui.min.js" type="text/javascript"></script> 
    <script type="text/javascript">
        $(function () {
            var divkuangH = $(window).height();            
            $("#detailsub").height(divkuangH - 225);
            //$("#dg").height(divkuangH - 235);
            $("#detail_data").combobox('select', 1);
        })
                
        //添加客户
        function AddTrust() {
            var url = "/BLL/Visa_Base/Base_TrustForm.aspx";
            top.openDialog(url, 'Menu_Form', '委托人列表信息 - 添加', 550, 230, 50, 50);
        }
        //添加供应商
        function AddSupply() {
            var url = "/BLL/Visa_Base/Base_SupplyForm.aspx";
            top.openDialog(url, 'Menu_Form', '供应商列表信息 - 添加', 600, 370, 50, 50);
        }
        //添加签证类型
        function AddCertType() {
            var url = "/BLL/Visa_Base/Base_CertTypeForm.aspx";
            top.openDialog(url, 'Menu_Form', '签证类型信息 - 添加', 300, 150, 50, 50);
        }

        function getselect() {
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                return row.infodetail_id;
            }
        }

        //删除
        function FDel() {
            var key = getselect();            
            if (IsDelData(key)) {
                $("#HDetailID").val(key);
                parm = 'action=DeleteInfoDetail&infoid=' + escape(key);
                
                showConfirmMsg('注：您确认要把此数据放入回收站吗？', function (r) {
                    if (r) {
                        getAjax(VisaInfo.ashx, parm, function (rs) {
                            if (parseInt(rs) > 0) {
                                showTipsMsg("删除成功！", 2000, 4);
                                ShowDetail();
                            } else if (parseInt(rs) == 0) {
                                showTipsMsg("删除失败，0 行受影响！", 3000, 3);
                            }
                            else {
                                showTipsMsg("<span style='color:red'>删除失败，请稍后重试！</span>", 4000, 5);
                            }
                        });
                    }
                });
            }
        }
        
        function Fadd() {   
            var cusname = $("#detail_cusname").val();
            var cusphone = $("#detail_cusphone").val();
            var cuscardno = $("#detail_cuscardno").val();
            var cusdata = $("#detail_data").combobox('getValue');
            var cus_operation = $('#detail_operation').combobox('getValue');
            var cprice = $('#detail_begmoney').val();
            var cityid = $('#detail_city').combobox('getValue');
            var certtypeid = $('#detail_type').combobox('getValue');            
            var certtypename = $('#detail_type').combobox('getText');
            var supplyid = '';
            var supplyname = '';
            var rmk = $('#detail_rmk').val();
            var infoid = $('#Hinfo').val();
            var detailid = $('#HDetailID').val();
            var viewPrice = $('#HD_viewPrice').val();
            
            if (cusname == "") {
                showTipsMsg("请填写客户姓名！", 2000, 5);
                return false;
            }
            if (cusdata == "") {
                showTipsMsg("请选择资料信息！", 2000, 5);
                return false;
            }

            if (cityid == "") {
                showTipsMsg("请选择签证国家！", 2000, 5);
                return false;
            }
            if (certtypeid == "") {
                showTipsMsg("请选择签证类型！", 2000, 5);
                return false;
            }

            if (viewPrice == "1") {
                if (!isDoubleOrNull(cprice)) {
                    showTipsMsg("请维护销售价！", 2000, 5);
                    return false;
                } 
            }
            
            //if (cusdata == "0") {
            //    if (cus_operation == "") {
            //        showtipsmsg("资料不齐全，必须维护操作员！", 2000, 5);
            //        return false;
            //    }
            //}
            if (cus_operation == "") {
                showTipsMsg("请维护操作员！", 2000, 5);
                return false;
            }
            //供应商 不是必填项            
            //checking
            //判断员工是否重复
            //添加新的类型是否成功
            //添加数据是否成功
            parm = 'action=InsertInfoDetail&cityid=' + escape(cityid) + '&certtype=' + escape(certtypeid) +
                   '&certtypename=' + escape(certtypename) + '&infoid=' + escape(infoid) +
                   '&supplyid=' + escape(supplyid) + '&supplyname=' + escape(supplyname) +
                   '&cusname=' + escape(cusname) + '&cusphone=' + escape(cusphone) +
                   '&cuscardno=' + escape(cuscardno) + '&cusdata=' + escape(cusdata) +                   
                   '&cus_operation=' + escape(cus_operation) + '&cprice=' + escape(cprice) +
                   '&cus_rmk=' + escape(rmk) + '&detailid=' + escape(detailid);
            
            getAjax('VisaInfo.ashx', parm, function (rs) {
                try {
                    var v_msg = rs;
                    if (v_msg.substring(0, 2) != "ok") {
                        $('#HD_errmsg').val(v_msg);
                        setTimeout(PopErr, 500);
                        //showWarningMsg(V_msg);
                        ////
                        return false;
                    } else {  
                        var tmp = v_msg.split('@');
                        var certtypeid = tmp[1];
                        var supplyid = tmp[2];
                       
                        //清空编辑状态
                        clearstatus();                        
                        ShowDetail();
                        $("#detail_cusname").select();
                        $("#detail_cusname").focus();
                    }
                    return false;
                } catch (e) {                   
                }
            });            
        }

        function PopErr() {
            var msg = $('#HD_errmsg').val();
            //showWarningMsg(msg);
            showTipsMsg("<span style='color:red'>" + msg + "</span>", 2000, 5);
        }
        
        function GetValueCustomer() {
            var v_name = $('#trust_id').combobox('getText');
            var v_id = $('#trust_id').combobox('getValue');
            if (v_id == undefined) { v_id = "s"; }
            $('#HCustomerid').val(v_id);
            $('#HCustomerName').val(v_name);
        }

        function ChangeCity() {
            var cityid = $('#detail_city').combobox('getValue');
            var trust_id = $('#trust_id').combobox('getValue');
            if (cityid == '') {
                return false;
            }
            if (trust_id == "")
            {
                showTipsMsg("请先选择委托方！", 2000, 5);
                return false;
            }
            
            var url = 'VisaInfo.ashx?action=GetCertType&cityid=' + escape(cityid);
            $('#detail_type').combobox({                
                url: url,
                valueField: 'id',
                textField: 'name'                
            });

            //显示可操作用户
            $('#detail_operation').combobox({
                url:'EasySelect.ashx?action=CityUser&cityid='+cityid,
                editable:false,
                valueField: 'user_id',
                textField: 'text'
            });            
        }

        function ChangeType() { 
            var cityid = $('#detail_city').combobox('getValue');
            var certtype = $('#detail_type').combobox('getValue');
            var trusttpye = $('#Htrusttype').val();
            //获取价格
            parm = 'action=GetPricebycitycert&cityid=' + escape(cityid) + '&certtype=' + escape(certtype) +
                   '&trusttype=' + escape(trusttpye);

            getAjax('VisaInfo.ashx', parm, function (rs) {
                try {
                    $('#detail_begmoney').val(rs);                    
                } catch (e) {
                }
            });

            ////供应商列表
            //var viewSupply = $("#HD_viewSupply").val();
            //if (viewSupply == "1") {
            //    if (cityid != "s" & certtype != "s") {
            //        var url = 'VisaInfo.ashx?action=GetSupplybycitycert&cityid=' + escape(cityid) + '&certtype=' + escape(certtype)
            //        $('#detail_supply').combobox({
            //            url: url,
            //            valueField: 'supply_id',
            //            textField: 'supply_name'
            //        });
            //    }
            //}
        }
        
        function ChangeTrust() {
            GetValueCustomer();
            var trustid = $("#HCustomerid").val();
            if (trustid != "s") {
                var parm = 'action=gettrustinfo&trust_id=' + escape(trustid);
                getAjax('/BLL/Visa_Base/base.ashx', parm, function (rs) {
                    try {
                        if (rs != "") {
                            var tmp = rs.split("@");
                            $("#Ref_trusttype").val(tmp[0]);
                            $("#info_operation").val(tmp[5]);

                            $('#Htrusttype').val(tmp[4]);

                            ChangeCity();
                        } 
                    } catch (e) {
                    }
                });
            }
        }

        function Fsave() {            
            GetValueCustomer();
            var infoid = $('#Hinfo').val();
            var trustid = $('#HCustomerid').val();
            var trust_name = $('#trust_id').combobox('getText');
            var operation = $('#info_operation').val();
            var raisedate = $('#info_getdate').val();
            var AddNo = $('#HD_AddNo').val();            
            var rows = $('#dg').datagrid('getRows').length;
            
            if (!IsNullOrEmpty(trustid)) {
                showTipsMsg("请选择委托方！", 2000, 5);
                return false;
            }
            if (!isDate(raisedate)) {
                showTipsMsg("请填写录入日期！", 2000, 5);
                return false;
            }
            if (rows == 0) {
                showTipsMsg("请先添加客户信息！", 2000, 5);
                return false;
            }
            if (!CheckDataValid('#form1')) {
                return false;
            }           
           
            parm = 'action=InsertInfo&infoid=' + escape(infoid) + '&AddNo=' + escape(AddNo) +
                   '&trust_id=' + escape(trustid) + '&trust_name=' + escape(trust_name) +
                   '&info_operation=' + escape(operation) + '&info_getdate=' + escape(raisedate);

            getAjax('VisaInfo.ashx', parm, function (rs) {
                try {
                    var v_msg = rs;
                    if (v_msg.substring(0, 2) != "ok") {
                        $('#HD_errmsg').val(v_msg);
                        setTimeout(PopErr, 500);                        
                        return false;
                    } else {
                        var tmp = v_msg.split('@');
                        var trustnewid = tmp[1];
                        if (trustid == 's') {
                            $('#trust_id').combobox('reload');
                            $("#trust_id").combobox('select', trustnewid);
                        }
                        if (AddNo == "0") {
                            //计算订单号
                            $('#HD_AddNo').val("1"); 
                        }
                        showTipsMsg("数据保存成功！", 2000, 4);
                        return true;
                    }                    
                } catch (e) {
                }
            });
            return true;
        }
        function FsaveAdd() {
            var isok = Fsave();
            if (isok) {
                FClear();
                $('#trust_id').combobox('clear');
                $('#info_operation').val('');
                $('#Ref_trusttype').val('');
            }            
        }

        function FEdit() {
            var key = getselect();
            if (IsEditdata(key)) {
                //var tt = "<span class=\"icon-botton\"  style=\"background: url('/Themes/images/16/add.png') no-repeat scroll 0px 4px; \"> </span>更 新";
                var tt = "<img src=\"/Themes/Images/16/add.png\" alt=\"\" />更 新";
                $('#lbtadd').html(tt);
                
                $("#HDetailID").val(key);

                var parm = 'action=GetInfoDetail&detailid=' + escape(key);
                getAjax('VisaInfo.ashx', parm, function (rs) {
                    try {
                        var V_JSON = rs;
                        var json = eval("(" + V_JSON + ")");
                        for (var i = 0; i < json.DETAIL.length; i++) {
                            var datas = json.DETAIL[i];

                            $("#detail_cusname").val(datas.INFODETAIL_USER);
                            $("#detail_cusphone").val(datas.INFODETAIL_USERPHONE);
                            $("#detail_cuscardno").val(datas.INFODETAIL_CARDNO);
                            $("#detail_data").combobox('select', datas.DATA_INTEGRITY);
                            $("#detail_city").combobox('select', datas.CITY_ID);
                            ChangeCity();
                            $("#detail_type").combobox('select', datas.REF_CERTTYPE);
                            $('#detail_begmoney').val(datas.INFODETAI_BEGPRICE);

                            //ChangeType(); //目前只有获取价格，因此可以不用
                            //$("#detail_supply").combobox('select', datas.SUPPLY_ID);
                            $("#detail_operation").combobox('select', datas.INFODETAIL_OPERATIONID);
                            $('#detail_rmk').val(datas.INFODETAIL_REMARK);
                        }
                    } catch (e) {
                    }
                });                    
            }
        }

        function ShowDetail() {
            var infoid = $('#Hinfo').val();
            var parm = 'action=DetailList&infoid=' + infoid;
            getAjax('EasySelect.ashx', parm, function (rs) {
                var V_JSON = rs;
                var json = eval("(" + V_JSON + ")");
                $('#dg').datagrid('loadData', json);                      
            });

            //$('#dg').datagrid({
            //    url: 'EasySelect.ashx?action=DetailList&infoid='+ infoid,
            //    method: 'get'
            //});
        }

        function FClear() {
            $("#detail_cusname").val("");
            $("#detail_cusphone").val("");
            $("#detail_cuscardno").val("");
            $("#detail_data").combobox('clear');
            $("#detail_city").combobox('clear');            
            $("#detail_type").combobox('clear');
            $("#detail_type").combobox('loadData', "");
            $('#detail_operation').combobox('clear');
            $('#detail_operation').combobox('loadData', "");
            
            $('#detail_begmoney').val(0); 
            $('#detail_rmk').val("");

            clearstatus();          
        }
        function clearstatus() {
            //清空编辑状态
            $('#HDetailID').val("")
            var tt = "<img src=\"/Themes/Images/16/add.png\" alt=\"\" />添 加";
            $('#lbtadd').html(tt);
        }
    </script>       
</head>
<body>    
    <form id="form1" runat="server">
    <input id="Hinfo" type="hidden" runat="server"  />            
    <input id="HDetailID" type="hidden" runat="server"/> 
    <input id="HD_viewSupply" type="hidden" runat="server"/>
    <input id="HD_viewPrice" type="hidden" runat="server"/>          
    <input id="HD_AddNo" type="hidden" runat="server" value="0"/>
    <input id="HD_errmsg" type="hidden" runat="server" />
    <input id="Htrusttype" type="hidden" runat="server" />        
   
    <input id="HCustomerid" type="hidden" runat="server"/>
    <input id="HCustomerName" type="hidden" runat="server"/>              
    <table border="0" cellpadding="0" cellspacing="0" class="frm">
        <tr>
            <th>
                <div>
                    <img alt="" src="/Themes/images/16/add.png" onclick="AddTrust()" border="0"
                        style="vertical-align: middle;" id="img_trust" runat="server" />委托方:
                </div>
            </th>
            <td>
                <input id="trust_id" runat="server" class="easyui-combobox" style="width:116px" 
                    data-options="onSelect:function(rec){ChangeTrust();},                        
                        url:'EasySelect.ashx?action=trustlist',
                        valueField: 'trust_id',
                        textField: 'name',
                        panelWidth:200
                    " />                 
            </td>
            <th>业务员:
            </th>
            <td>
                <input id="info_operation" runat="server" type="text" class="txt" style="width:110px" />
            </td>
            <th>委托方类型:
            </th>
            <td>
                <input id="Ref_trusttype" runat="server" type="text" class="txt" readonly="readonly" style="width:110px" />
            </td>
            <th>收签时间:</th>
            <td>
                <input id="info_getdate" runat="server" type="text" class="txt" datacol="yes" err="收签时间"
                    style="width:110px" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd' })" />
            </td>
        </tr>
        <tr>
            <td colspan="8">
                <div class="frmtop">
                    <div>添加客户信息</div>
                </div>
            </td>
        </tr>
        <tr>
            <th>客人姓名:
            </th>
            <td>
                <input id="detail_cusname" runat="server" type="text" class="txt" style="width:110px" />
            </td>
            <th>客人电话:
            </th>
            <td>
                <input id="detail_cusphone" runat="server" type="text" class="txt" style="width:110px" />
            </td>
            <th>护照号:
            </th>
            <td>
                <input id="detail_cuscardno" runat="server" type="text" class="txt" style="width:110px" />
            </td>
            <th>资料:
            </th>
            <td>
                <input id="detail_data" runat="server" class="easyui-combobox" style="width:116px"
                    data-options="editable:false,
                        url:'EasySelect.ashx?action=datalist',
                        valueField: 'property_key',
                        textField: 'property_value'    
                    "/>                
            </td>
        </tr>
        <tr>
            <th>签证国家:
            </th>
            <td>
                <input id="detail_city" runat="server" class="easyui-combobox" style="width:116px" 
                    data-options="                        
                        onSelect:function(rec){ChangeCity();},
                        url:'EasySelect.ashx?action=citylist',
                        valueField: 'city_id',
                        textField: 'city_name',
                        panelWidth:200
                    " />
            </td>
            <th>
                签证类型:
            </th>
            <td>                
                <input id="detail_type" runat="server" class="easyui-combobox" style="width:116px"
                    data-options="editable:false,panelWidth:200,onSelect:function(rec){ChangeType();}"/>
            </td>
            <th><div id="div_price1" runat="server">销售额:</div>
            </th>
            <td><div id="div_price2" runat="server">
                <input id="detail_begmoney" runat="server" type="text" class="txt" readonly="readonly"
                     style="width:110px" />
                </div>
            </td>
            <th>操作员:                
            </th>
            <td>
                 <input id="detail_operation" runat="server" class="easyui-combobox" style="width:116px"
                      data-options="editable:false"/> 
            </td>
        </tr>
        <tr>
            <th>备注:</th>
            <td colspan="5">
                <textarea id="detail_rmk" class="txtRemark" runat="server" style="width: 98%; height: 50px;"></textarea>
            </td>
            <td colspan="2" style="text-align: center">
                <a class="l-btn" href="javascript:void(0)" onclick="return Fadd();"><span id="lbtadd" class="l-btn-left">
                    <img src="/Themes/Images/16/add.png" alt="" />添 加</span></a>
                <a class="l-btn" href="javascript:void(0)" onclick="return FDel();"><span class="l-btn-left">
                    <img src="/Themes/Images/16/delete.png" alt="" />删 除</span></a>
                <a class="l-btn" href="javascript:void(0)" onclick="return FEdit();"><span class="l-btn-left">
                    <img src="/Themes/Images/16/edit.png" alt="" />编 辑</span></a>
                <a class="l-btn" href="javascript:void(0)" onclick="return FClear();"><span class="l-btn-left">
                    <img src="/Themes/Images/16/redo.png" alt="" />重 填</span></a> 
            </td>
        </tr>
    </table>
     
    <div id="detailsub" style="width:100%;height:100%; overflow-y:scroll;overflow-x:hidden">
        <table id="dg" class="easyui-datagrid" style="width:100%;"
			data-options="rownumbers:true,singleSelect:true,fitColumns:true,method:'get',autoRowHeight:false,url:null ">
		    <thead>
			    <tr>
				    <th data-options="field:'ck',checkbox:true"></th>
                    <th data-options="field:'infodetail_id', hidden:true">id</th>
				    <th data-options="field:'infodetail_user',width:80">客人姓名</th>
				    <th data-options="field:'infodetail_userphone',width:70">客人电话</th>
                    <th data-options="field:'infodetail_cardno',width:70">护照号</th>
				    <th data-options="field:'dataname',width:30">资料</th>
                    <th data-options="field:'city_name',width:80">签证国家</th>
                    <th data-options="field:'property_value',width:160">签证类型</th>
                    <th data-options="field:'infodetai_begprice',width:60,align:'right'">销售额</th>
				    <th data-options="field:'infodetail_operationname',width:60">操作员</th>
				    <th data-options="field:'infodetail_remark',width:160">备注</th>
			    </tr>
		    </thead>
	    </table> 
        
    </div>    
    <div class="frmbottom">
        <asp:LinkButton ID="SaveAdd" runat="server" class="l-btn" OnClientClick="return FsaveAdd();" 
            OnClick="SaveAdd_Click"><span class="l-btn-left"><img src="/Themes/Images/save.png" />新 增</span>
        </asp:LinkButton>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <a class="l-btn" href="javascript:void(0)" onclick="return Fsave();"><span class="l-btn-left">
                    <img src="/Themes/Images/save.png" alt="" />保 存</span></a> 
    </div>
    </form>
</body>
</html>
